package com.atguigu.webflux.utils;

import java.security.SecureRandom;

public class RandomStringGenerator {

    private static final String ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    public static void main(String[] args) {
        String timestampPart = generateTimestampPart();
        String randomAlphaPart = generateAlphaString(28); // 根据需要调整长度

        String result = timestampPart + randomAlphaPart;
        System.out.println(result);
    }

    public static String generateTimestampPart() {
        double millis = System.currentTimeMillis(); // 毫秒
        double fractional = Math.random(); // 添加小数部分
        double timestamp = millis + fractional;
        return String.format("%.9f", timestamp);
    }

    public static String generateAlphaString(int length) {
        SecureRandom random = new SecureRandom();
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(ALPHA.length());
            sb.append(ALPHA.charAt(index));
        }
        return sb.toString();
    }
}